<?php
@session_start();

if (isset($_POST['btnSubmit'])) {
    $u = $_POST['txtUser'];
    $p = $_POST['txtPass'];
    $url = $_POST['url'];

    require '../db.php';
    
    $query = "select * from tbl_users where email = '$u' and password = '$p'";
    $result = connect($query);
    $row = mysql_fetch_array($result);

    if ($row) {
        $_SESSION['user'] = $row['full_name'];
        
        if (isset($_POST['chkRemember'])) {
            setcookie('user', $u, time() + 3600, "/gasshop/", NULL);
            setcookie('pass', $p, time() + 3600, "/gasshop/", NULL);
        }
        
        header("location: $url");
    } else {
        header("location:../login.php");
    }
}

